package ru.edu.vstu.atpp.acm.ui.services.encoder;

import org.apache.tapestry5.ValueEncoder;
import ru.edu.vstu.atpp.acm.ui.entities.Groups;
import ru.edu.vstu.atpp.acm.ui.services.dao.GroupsDAO;

/**
 * Энкодер для групп
 */
public class GroupsEncoder implements ValueEncoder<Groups> {

    private GroupsDAO groupsDAO;

    public GroupsEncoder(GroupsDAO pGroupsDAO) {
        groupsDAO = pGroupsDAO;
    }

    @Override
    public String toClient(Groups groups) {
        return groups.getIdGrp().toString();
    }

    @Override
    public Groups toValue(String s) {
        return groupsDAO.getById(Long.parseLong(s));
    }
}
